package com.zhousb.deviceManager.controller;

import com.zhousb.deviceManager.common.R;
import com.zhousb.deviceManager.common.ResponseResult;
import com.zhousb.deviceManager.model.bo.CreateAssetByInventoryBO;
import com.zhousb.deviceManager.model.entity.KtWxUserConfig;
import com.zhousb.deviceManager.security.JwtUser;
import com.zhousb.deviceManager.service.WxInventoryService;
import com.zhousb.deviceManager.service.WxUserConfigService;
import com.zhousb.deviceManager.utils.AuthUtils;
import com.zhousb.deviceManager.utils.JwtUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/wxInventory")
public class WxInventoryController {

    @Resource
    private WxInventoryService wxInventoryService;
    @Resource
    private WxUserConfigService wxUserConfigService;
    @Resource
    AuthUtils authUtils;


    @RequestMapping(value = "/order/create",headers = "content-type=multipart/form-data")
    public ResponseResult createOrder(MultipartFile file) throws IOException {
        JwtUser jwtUser = authUtils.getUser();
        String userTel =jwtUser.getUserTel();
        return R.success(wxInventoryService.create(userTel,file));
    }

    @GetMapping("/order/current")
    public ResponseResult current(){
        return R.success(wxInventoryService.current());
    }

    @GetMapping("/order/list")
    public ResponseResult list(Integer current,String inventoryId){
        return R.success(wxInventoryService.list(current,inventoryId));
    }

    @GetMapping("/order/scanned")
    public ResponseResult scanned(Integer current,String inventoryId,String keyword){
        JwtUser jwtUser = authUtils.getUser();
        String phone =jwtUser.getUserTel();
        return R.success(wxInventoryService.scanned(current,inventoryId,keyword));
    }

    @GetMapping("/checkCode")
    public ResponseResult checkCode(String inventoryId,String code){
        return R.success(wxInventoryService.checkCode(inventoryId,code));
    }

    @PostMapping("/submit/asset")
    public ResponseResult submitAsset(@RequestBody CreateAssetByInventoryBO bo){
        return R.success(wxInventoryService.submitAsset(bo));
    }

    @PostMapping("/submit/order")
    public ResponseResult submitOrder(String inventoryId){
        return R.success(wxInventoryService.submitOrder(inventoryId));
    }

    @PostMapping("/reset")
    public ResponseResult reset(String inventoryId){
        return R.success(wxInventoryService.reset(inventoryId));
    }

    @PostMapping("/cancel")
    public ResponseResult cancel(String inventoryId){
        return R.success(wxInventoryService.cancel(inventoryId));
    }

    @GetMapping("/config")
    public ResponseResult getUserConfig(){
        String phone = authUtils.getUser().getUserTel();
        return R.success(wxUserConfigService.getUserConfig(phone));
    }

    @PostMapping("/config")
    public ResponseResult setUserConfig(@RequestBody KtWxUserConfig bo){
        return R.success(wxUserConfigService.setUserConfig(bo));
    }

    @PostMapping("/uploadImage")
    public ResponseResult uploadImage(MultipartFile file){
        return R.success(wxInventoryService.uploadImage(file));
    }

    @PostMapping("/export")
    public ResponseResult export(){
        return R.success(wxInventoryService.export());
    }

}
